from msvcrt import getch
import os
import sys

class Board:
	def __init__(self):
		self.board = [
			['#', '#', '#', '#', '#', '#', '#', '#', '#', '#'],
			['#', ' ', '#', ' ', ' ', '#', '#', ' ', ' ', '#'],
			['#', ' ', '#', '#', ' ', ' ', ' ', ' ', '#', '#'],
			['#', ' ', '#', '#', ' ', '#', '#', '#', ' ', '#'],
			['#', ' ', ' ', ' ', ' ', '#', '#', '#', ' ', '#'],
			['#', '#', '#', '#', ' ', '#', '#', '#', ' ', '#'],
			['#', '#', ' ', '#', ' ', '#', '#', ' ', ' ', '#'],
			['#', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#'],
			['#', '#', '#', '#', '#', '#', '#', ' ', ' ', '#'],
			['#', '#', '#', '#', '#', '#', '#', '#', ' ', '#'],
			['#', '#', '#', '#', '#', '#', '#', '#', ' ', '#'],
			['#', ' ', '#', ' ', ' ', '#', '#', ' ', ' ', '#'],
			['#', ' ', '#', '#', ' ', ' ', ' ', ' ', ' ', '#'],
			['#', ' ', '#', '#', ' ', '#', '#', '#', ' ', '#'],
			['#', ' ', ' ', ' ', ' ', '#', '#', '#', ' ', '#'],
			['#', '#', '#', '#', ' ', '#', '#', '#', ' ', '#'],
			['#', '#', ' ', '#', ' ', '#', '#', ' ', ' ', '#'],
			['#', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#'],
			['#', '#', '#', '#', '#', '#', '#', ' ', ' ', '#'],
			['#', '#', '#', '#', '#', '#', '#', '#', '#', '#']
		]
	
	def setPosition(self, x, y, ch):
		self.board[x][y] = ch
	
	def getPosition(self, x, y):
		return self.board[x][y]
	
	def printBoard(self):
		for row in self.board:
			for col in row:
				sys.stdout.write(col)
			print

class Player:
	def __init__(self):
		self.pchar = 'P'
		self.x = 1
		self.y = 1
		self._x = self.x
		self._y = self.y
	
	def move(self):
		
		self._x = self.x
		self._y = self.y
		
		moved = True
		key = ord(getch())
		if key == 72 and board.getPosition(player.x - 1, player.y) != "#": #Up
			self.x -= 1
			player.pchar = '^'
		elif key == 80 and board.getPosition(player.x + 1, player.y) != "#": #Down
			self.x += 1
			player.pchar = 'v'
		elif key == 75 and board.getPosition(player.x, player.y - 1) != "#": #Left
			self.y -= 1
			player.pchar = '<'
		elif key == 77 and board.getPosition(player.x, player.y + 1) != "#": #Right
			self.y += 1
			player.pchar = '>'
		elif key == 27: #ESC
			exit()
		else:
			moved = False
		
		return moved

def clearScreen():
	os.system("cls")

	
board = Board()
player = Player()

while True:
	moved = player.move()
	if moved:
		clearScreen()
		board.setPosition(player._x, player._y, " ")
		board.setPosition(player.x, player.y, player.pchar)
		board.printBoard()
	